﻿
var num = 0;
var page = 1;
var keyword = ""; //关键词
var hannelid = ""; //频道id
var authid = ""; //作者id
var hid = "";
var type = "";
var pagecount = "0";
var pagesum = 0;
var itemCount = 0;
$(document).ready(function () {

    $(".selectsreachimg").click(function () {
        var url = $(".selectsreachtxt").val();

        if (CheckUrl(url)) {
            if (url.indexOf('http') == -1) {
                url = "http://" + url;
            }

            if (url.indexOf(window.location.host) != -1) {
                toast.show("不允许分享内部网页");
                return;
            }
            window.location.href = "url-edit.html?url=" + encodeURIComponent(url);
            //window.location.href = "to_detail.aspx?type=2&url=" + encodeURIComponent(url);
            //window.location.href = "detail.html?is_app=1&type=2&url=" + encodeURIComponent(url);
        }
        else {
            Alert("请输入正确网址");

            //            page = 1;
            //            $(".tg_select").html("");
            //            load(url, page);
        }

    });

    //    if (null != getUrlArgStr("Keyword")) {
    //        keyword = decodeURI(getUrlArgStr("Keyword"));
    //    }
    //    if (null != getUrlArgStr("hannelid")) {
    //        hannelid = getUrlArgStr("hannelid");
    //    }
    // load(keyword, 1);
    load(1);
    var scollH = $("#wrapper").height();
    $("#wrapper").bind("scroll", function () {
        //当滚动条滚动时

        var scollTop = $("#wrapper").scrollTop() + $("#wrapper").height();
      
        if (scollTop - scollH > 500) {
       
            if (wait.isShow) { return; } //如果正在加载，则返回          
            page++;
            scollH = scollTop;
            load(page);
        }
        return false;
    });


});

//function load(keyword, page) {
//   
//    if (!islogin()) { window.location.href = 'login.html'; return; }
//    if (pagecount == "1") {return;}
//    ajax.getarticleList("channel_id=" + hannelid + "&author_id=" + authid + "&key_word=" + keyword + "&page_index=" + page, function (data) {
//        if (data.code == "4") { Alert("没有相关文章"); return; }
//        if (data.item.pageCount < page) {
//            if (pagecount == "0")
//                Alert('到底了！');
//            pagecount = "1";
//            return;
//        }
//        $(".topcententxt").html("选择文章 (" + data.item.itemCount + ")");

//        $(data.item.table).each(function () {
//            num++;
//            var logoimg = this.logo == "" ? "img/30.png" : this.logo;
//            var titles = this.title;
//            if (titles.length > 12)
//                titles = titles.substr(0, 12) + "...";
//            $(".tg_select").append("<div class=\"centenlist\"><div class=\" centenimg\"><img src=\"" + logoimg + "\" /></div><div class=\"cententxt\" onclick=\"window.location.href='to_detail.aspx?article_id=" + this.id + "'\"><div class=\"cententxttop\">" + titles + "</div><div class=\"centenTime\"> " + this.date.substr(0, 10) + "<div class=\"centenflow\"><img src=\"img/flow.jpg\" />  " + this.click + "</div><div class=\"check\"><img src=\"\" class=\"checkimg\"  /><input type=\"hidden\" name=\"checkid\" value=\"" + this.id + "\" /></div></div></div></div>");
//        });
//        // loadhtml();
//    });
//    }

//    function loadhtml() {
//        $(".selectsreachtxt").val($(this).parent().parent().parent().children().children().attr("href"));
//        hid = $(this).next().val();
//    }

function load(page) {
    if (pagecount == "1") { return; }
    if (!islogin()) { window.location.href = 'login.html'; return; }
    ajax.GetSharelist("is_other=1&page_index=" + page, function (data) {
        if (data.code == "4") { Alert(data.msg.toString()); pagecount = "1"; return; }
        if (data.item.pageCount < page) {
            if (pagecount == "0")
                Alert('到底了！');
            pagecount = "1"; return;
        }
        itemCount = data.item.itemCount;
        $(".topcententxt").html("我的转发 (" + data.item.itemCount + ")");


        $(data.item.table).each(function () {
            num++;
            var logoimg = this.article_logo == null ? "img/30.png" : this.article_logo;

            var titles = "";
            if (this.type == 1) {
                titles = this.article_title;
            }
            else if (this.type == 2) {
                titles = this.url_title;
                if (this.url_logo != null && this.url_logo != "")
                    logoimg = this.url_logo;
                
            }

            if (titles != null && titles.length > 12)
                titles = titles.substr(0, 12) + "...";


            $(".tg_select").append("<div class=\"centenlist\"><div class=\" centenimg\"><img src=\"" + logoimg + "\"  /></div><div class=\"cententxt\" onclick=\"window.location.href='to_detail.aspx?shared_id=" + this.id + "'\" ><div class=\"cententxttop\"><strong>" + titles + "</strong></div><div class=\"centenTime\">" + this.date.substr(0, 10) + "<div class=\"centenflow\" style='width:100px;' name=\"" + this.id + "\" > <div style='width: 50px;float: left;'  ><img src=\"img/flow.jpg\" class=\"imgclick\" name=\"" + this.id + "\" /> " + this.click + "</div> <div><img src=\"img/dianji1.png\"  class=\"imgclick\" name=\"" + this.id + "\" /> " + this.ad_click + "</div></div><div class=\"check\"><img src=\"img/Delete2.jpg\" class=\"checkimg\"  /><input type=\"hidden\" name=\"checkid\" value=\"" + this.id + "\" /></div></div></div></div>");
        });

        loadhtml();


    });
}

function loadhtml() {
    $(".check").click(function () {
        if (confirm($(this).parent().parent().parent().find('strong').html() + "\n\n  确定删除？")) {

            RemoveShare($(this).children(":last").val(), $(this));
        }
        return false;
    });

    $(".centenflow").click(function () {
        $(this).css("color", "#F37B0B");
        window.location.href = "Statistical.html?Shareid=" + $(this).attr("name") + "&type=Share";
        return false;
    });

}

function RemoveShare(id, obj) {
    if (!islogin()) { window.location.href = 'login.html'; return; }
    ajax.RemoveShare("id=" + id, function (data) {
        if (data.msg.toString() == "成功") {
            obj.parent().parent().parent().hide(500) ;
            $(".topcententxt").html("我的转发 (" + --itemCount + ")");
        }
        else {
            Alert(data.msg.toString());
        }
    });

}


 